#!/bin/bash
#
# Script for add, delete and manage users on remote servers
# Ermakov Konstantin 05.04.2011
#
# $Id: user_del.sh 150 2011-04-06 17:00:59Z mamartynov@gmail.com $
#

. $OPENARS_HOME/common/debug.h || exit 1
#. $OPENARS_HOME/common/functions.h || exit 1

user=$USER_ARS
[ -z "$user" ] && user=$LOGNAME
[ -z "$1" ] || [ -z "$2" ] && { ERR "not enough parameters"; exit 1; }
[ ! -f "$1" ] && { ERR "not found file \"$1\""; exit 1; }

srvlist=`cat $1`
deluser=$2

INF "count hosts: `echo $srvlist | wc -w`"
INF "del user: $deluser"

for server in $srvlist
do
if [ ! -z "$USER_ARS" ]; then
    ( SSH $USER_ARS@$server "sudo /usr/sbin/userdel -r $deluser"; [ "$?" -ne 0 ] && ERR "Error uderdel $deluser on server $server" ) &
fi
done

WAIT 180

exit 0

